import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { SignItemSub } from './SignItemSub';
import { BaseItem } from '../../items/BaseItem';
import { _player } from '../../Main';
const { ccclass, property } = _decorator;

@ccclass('SignItem')
export class SignItem extends Component {

    @property(Sprite)
    bottom: Sprite = null!
    
    @property(Label)
    dayNode: Label = null!

    @property(Node)
    mask: Node = null!

    @property(SignItemSub)
    signItemSubs: SignItemSub[] = []

    day: number = 1

    init(day: number, items: { item: BaseItem, amount: number }[]) {
        this.day = day
        this.dayNode.string = this.day + ''
        for (let i = 0; i < this.signItemSubs.length; i++) {
            let item = items[i]
            let sis: SignItemSub = this.signItemSubs[i]
            if (!item) {
                sis.node.active = false
                continue
            }
            sis.init(item.item, item.amount)
        }
    }

    refreshState(signed: boolean, bottoms: SpriteFrame[]) {
        this.mask.active = signed
        this.bottom.spriteFrame = bottoms[this.day == _player.data.signDay ? 1 : 0]
    }

    get(multi: number) {
        for (let i = 0; i < this.signItemSubs.length; i++) {
            let signItemSub: SignItemSub = this.signItemSubs[i]
            if (!signItemSub.node.active) {
                continue
            }
            signItemSub.get(multi)
        }
    }
}


